//
//  ZYViewController.m
//  ALearningWalk
//
//  Created by 张勇 on 16/7/2.
//  Copyright © 2016年 战斗民族. All rights reserved.
//

#import "ZYCollectionViewController.h"
#import "ZYCollectionTableViewCell.h"
#import "smallListModel.h"
#import "findDetailViewController.h"
@interface ZYCollectionViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,retain)UITableView *myTableView;

@property(nonatomic,retain)NSMutableArray *myArray;

@end

@implementation ZYCollectionViewController

-(void)viewWillAppear:(BOOL)animated{

    [self.myTableView reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back_h"]  style:UIBarButtonItemStylePlain target:self action:@selector(Action:)];
    
    self.myArray = [NSMutableArray array];
    self.myArray = [[DataBaseHandle shareDataFMDBHandle]selectAll];
    
    self.myTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.myTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.myTableView];
    
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    
    [self.myTableView registerClass:[ZYCollectionTableViewCell class] forCellReuseIdentifier:@"cellReuse"];
    
    [self.myTableView reloadData];
    self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    // Do any additional setup after loading the view.
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    smallListModel *model = [self.myArray objectAtIndex:indexPath.row];
    findDetailViewController *findVc = [[findDetailViewController alloc] init];
    findVc.albumid = model.albumId;
    // 隐藏状态栏及底部栏
    findVc.hidesBottomBarWhenPushed = YES;
    //self.navigationController.navigationBar.hidden = YES;
    [self.navigationController pushViewController:findVc animated:YES];

}
//cell高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 100;
}
//cell个数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myArray.count;

}
//显示cell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ZYCollectionTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellReuse"];
    if (cell == nil) {
        cell = [[ZYCollectionTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellReuse"];
    }
   
    smallListModel *model = [self.myArray objectAtIndex:indexPath.row];
    cell.model = model;
    return cell;

 
}

//返回上一级
-(void)Action:(UIBarButtonItem *)bar{
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
